#include "widget.h"
#include "ui_widget.h"
#include <QSerialPortInfo>
#include <QSerialPort>
#include <QDebug>
void Widget::initDefault()
{
    ui->comboBox_boautrate->
            addItems({"4800","9600","19200","38400","57600","74880","115200","230400",
                     "460800","57600"});
    //添加数据位

//    QSerialPort::DataBits::Data5::
//    QSerialPort::DataBits
    ui->comboBox_databit->addItems({
                                       "5","6","7","8","NONE"
                                   });
    //校验位
    ui->comboBox_checkbit->addItems({
                                       "None","Even","Mark","Space"
                                    });
    //停止位
    ui->comboBox_stopbit->addItems({
                                       "One","Oneandhalf","Two","No"
                                   });
    //流控
    ui->comboBox_streamctrl->addItems({"NO","Soft","Hard","None"});

    //统一设置下宽度
    ui->comboBox_boautrate->setMinimumWidth(120);
    ui->comboBox_databit->setMinimumWidth(120);
    ui->comboBox_checkbit->setMinimumWidth(120);
    ui->comboBox_stopbit->setMinimumWidth(120);
    ui->comboBox_streamctrl->setMinimumWidth(120);

//    ui->spinBox_ms->
//    ui->spinBox_ms->setValue(500);
    ui->lineEdit_send_text->setText("Hello,World！");
    ui->lineEdit_ms_times->setText("1000");
}

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->setLayout(ui->gridLayout_groal);

    //添加波特率的几个选项
    initDefault();
    //获得当前电脑可用的所有串口
    QList<QSerialPortInfo> serialPortInfos
            = QSerialPortInfo::availablePorts();

    QStringList qsl;
    for(QSerialPortInfo info : serialPortInfos){
        qsl.append(info.portName());
    }
    ui->comboBox_serialnum->addItems(qsl);

}

Widget::~Widget()
{
    delete ui;
}

